package com.mikasa.springboot.example.controller;

import com.alibaba.fastjson.JSON;
import com.mikasa.springboot.example.domain.User;
import com.mikasa.springboot.example.rabbitmq.content.ContractRabbitmq;
import com.mikasa.springboot.example.rabbitmq.content.TenantRabbitmq;
import com.mikasa.springboot.example.rabbitmq.demo.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by User on 17/1/16.
 */

@RestController
@RequestMapping(value = "/rabbitmq")
public class RabbitMqController {

    @Autowired
    private Sender sender;

    /*@Autowired
    private ContractRabbitmqService contractRabbitmqService;*/

    @RequestMapping(value = "hello", method = RequestMethod.GET)
    public void hello() throws Exception {
        String context = "hello " + new Date();
        sender.send(context);
        User user = new User();
        user.setId(1);
        user.setPassword("123654");
        user.setPhone("13011111111");
        user.setUsername("sherlock");
        sender.send(JSON.toJSONString(user));
        String context1 = "hi, i am message 1";
        sender.send1(context1);
        sender.send2(user);
    }

    /*@RequestMapping(value = "contract/direct", method = RequestMethod.GET)
    public void contractDirect(String content) {
        ContractRabbitmq contract = new ContractRabbitmq();
        contract.setDateCreated(new Date());
        contract.setId(12L);
        contract.setName("liuhan");
        List<String> strList = new ArrayList<>();
        strList.add("liu");
        strList.add("test str");
        contract.setTestStrList(strList);
        contractRabbitmqService.sendContractRabbitmqDirect(contract);
    }

    @RequestMapping(value = "contract/topic", method = RequestMethod.GET)
    public void contractTopic(String content) {
        ContractRabbitmq contract = new ContractRabbitmq();
        contract.setDateCreated(new Date());
        contract.setId(12L);
        contract.setName("liuhan");
        List<String> strList = new ArrayList<>();
        strList.add("liu");
        strList.add("test str");
        contract.setTestStrList(strList);
        contractRabbitmqService.sendContractRabbitmqTopic(contract);
    }

    @RequestMapping(value = "tenant/direct", method = RequestMethod.GET)
    public void tenantDirect(String content) {
        TenantRabbitmq tenant = new TenantRabbitmq();
        tenant.setId(12L);
        tenant.setName("liuhan");
        contractRabbitmqService.sendTenantRabbitmqDirect(tenant);
    }

    @RequestMapping(value = "tenant/topic", method = RequestMethod.GET)
    public void tenantTopic(String content) {
        TenantRabbitmq tenant = new TenantRabbitmq();
        tenant.setId(12L);
        tenant.setName("liuhan");
        contractRabbitmqService.sendTenantRabbitmqTopic(tenant);
    }*/
}
